{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-24T11:21:25.233800Z",
     "start_time": "2021-11-24T11:21:25.213800Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "120"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "824464"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def gen():\n",
    "    for x in range(100000):\n",
    "        yield x\n",
    "        \n",
    "# 生成器\n",
    "my_gen = gen()\n",
    "# 列表\n",
    "my_list = [x for x in range(100000)]\n",
    "\n",
    "import sys\n",
    "\n",
    "sys.getsizeof(my_gen)\n",
    "\n",
    "sys.getsizeof(my_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-11-24T11:21:43.794800Z",
     "start_time": "2021-11-24T11:21:43.781800Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "87624"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "120"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表推导式\n",
    "my_list = [x for x in range(10000)]\n",
    "\n",
    "# 生成器表达式\n",
    "my_gen  = (x for x in range(10000))\n",
    "\n",
    "sys.getsizeof(my_list)\n",
    "\n",
    "sys.getsizeof(my_gen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#周三夜校课后作业"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-12-01T10:51:04.672604Z",
     "start_time": "2021-12-01T10:50:44.197604Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "已读取: 1W条。\n",
      "已读取: 2W条。\n",
      "已读取: 3W条。\n",
      "已读取: 4W条。\n",
      "已读取: 5W条。\n",
      "已读取: 6W条。\n",
      "已读取: 7W条。\n",
      "已读取: 8W条。\n",
      "已读取: 9W条。\n",
      "已读取: 10W条。\n",
      "已读取: 11W条。\n",
      "已读取: 12W条。\n",
      "已读取: 13W条。\n",
      "已读取: 14W条。\n",
      "已读取: 15W条。\n",
      "已读取: 16W条。\n",
      "已读取: 17W条。\n",
      "已读取: 18W条。\n",
      "已读取: 19W条。\n",
      "已读取: 20W条。\n",
      "已读取: 21W条。\n",
      "已读取: 22W条。\n",
      "已读取: 23W条。\n",
      "已读取: 24W条。\n",
      "已读取: 25W条。\n",
      "已读取: 26W条。\n",
      "已读取: 27W条。\n",
      "已读取: 28W条。\n",
      "已读取: 29W条。\n",
      "已读取: 30W条。\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "def read_csv_partly(file):\n",
    "    file_data = pd.read_csv(file, engine='python', encoding='gbk', chunksize = 10000)\n",
    "    for df_tmp in file_data:\n",
    "        yield df_tmp\n",
    "li = (x for x in pd.read_csv('./out.csv', engine='python', encoding='gbk', chunksize = 10000))\n",
    "\n",
    "i = 1\n",
    "for df in li:\n",
    "    print('已读取: {}W条。'.format(i))\n",
    "    with open('小文件{}.csv'.format(i),'w', newline = '') as f:\n",
    "        df.to_csv(f,index =False)\n",
    "    i += 1\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
